package cn.bdqn.service.impl;


import cn.bdqn.bean.result.Page;
import cn.bdqn.domain.PurchaseInfo;
import cn.bdqn.mapper.PurchaseInfoMapper;
import cn.bdqn.service.PurchaseInfoService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * (Purchaseinfo)表服务实现类
 *
 * @author makejava
 * @since 2020-09-21 10:58:41
 */
@Service("purchaseInfoService")
public class PurchaseInfoServiceImpl implements PurchaseInfoService {
    @Resource
    private PurchaseInfoMapper purchaseinfoMapper;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public PurchaseInfo queryById(Integer id) {
        return purchaseinfoMapper.queryById(id);
    }

    /**
     * 分页显示
     * 查询多条数据
     *
     */
    @Override
    public Page<PurchaseInfo> queryAll(Integer starNum, PurchaseInfo purchaseinfo) {
        Page page =new Page();
        PageHelper.startPage(starNum !=null ?starNum :1,page.getPageSize());
        List<PurchaseInfo> purchaseinfos=purchaseinfoMapper.queryAll(purchaseinfo);
        PageInfo<PurchaseInfo> pageInfo=new PageInfo(purchaseinfos);
        page.setMenuList(pageInfo.getList());
        return page;
    }

    /**
     * 新增数据
     *
     * @param purchaseinfo 实例对象
     * @return 实例对象
     */
    @Override
    public PurchaseInfo insert(PurchaseInfo purchaseinfo) {
        this.purchaseinfoMapper.insert(purchaseinfo);
        return purchaseinfo;
    }
    /**
     * 修改数据
     *
     * @param purchaseinfo 实例对象
     * @return 实例对象
     */
    @Override
    public PurchaseInfo update(PurchaseInfo purchaseinfo) {
        this.purchaseinfoMapper.update(purchaseinfo);
        return this.queryById(purchaseinfo.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.purchaseinfoMapper.deleteById(id) > 0;
    }
}